import { handleActions } from 'redux-actions'
import { success } from '../ui-components'

const init = {
  flows: {},
  invitationUrl: '',
  roles: [],
  tasks: [],
  importedUser: {}
};

export default handleActions({
  'fetch onboarding unhandled tasks': (state, { payload }) => ({
    ...state,
    tasks: payload
  }),
  'reset onboarding flows': (state) => ({
    ...state,
    ...init
  }),
  'fetch onboarding flows': (state, { payload }) => ({
    flows: payload
  }),
  'fetch invitation url': (state, { payload }) => {
    return {
      ...state,
      invitationUrl: payload
    }
  },
	'create onboarding flow': (state, { payload }) => {
		success('创建入职成功')
		payload()
		return state
	},
  'fetch role': (state, { payload }) => {
    return {
      ...state,
      roles: payload
    }
  },
  'fetch onboarding imported users': (state, { payload }) => ({
    ...state,
    importedUser: payload
  })
}, init)
